package com.xh.controller.view;

import com.xh.service.BlogService;
import com.xh.vo.Blog;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class viewController {
    @Resource
    private BlogService blogService;
    @GetMapping("toUpdatePwd")
    public String toUpdatePwd(){
        return "blog/updatePwd";
    }
    @GetMapping("updateHead")
    public String updateHead(){
        return "blog/upHead";
    }
    @GetMapping("toDeleteBAdmin")
    public String toDeleteBAdmin(HttpSession session, Model model){
        Integer id = (Integer) session.getAttribute("id");
        List<Blog> blogList = blogService.getBlogListByUserId(id);
        model.addAttribute("blogList",blogList);
        return "blog/deleteBAdmin";
    }
    @GetMapping("/deleteBlog/{bId}")
    public String deleteBlog(@PathVariable String bId){
        int i = Integer.parseInt(bId);
        blogService.deleteBlog(i);
        return "redirect:/toDeleteBAdmin";
    }
    @GetMapping("toAbout")
    public String toAbout(){
        return "blog/about";
    }
}
